package com.mhtvs;

//http://www.beanizer.org/site/index.php/en/Articles/Java-ssh-tunneling-with-jsch.html
//http://www.androidsnippets.com/encryptdecrypt-strings

import com.mhtvs.R;
import android.widget.VideoView;
import android.net.Uri;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
// think this is for audio only though...
//import android.webkit.WebViewClient;
import android.widget.MediaController;
//import android.app.ProgressDialog;

//---------------------------------------------------------------
//Development source for MHTVS CLIENT
//"Android client for use with MHTVS"
//Copyright (c) 2011, Doug Thompson, perladdict@gmail.com
//All rights reserved.
//
//http://code.google.com/p/mhtvs/
//
//View Demo here:
//http://www.youtube.com/watch?v=v4M2uVrMrGk
//
//Redistribution and use in source and binary forms, with or
//without modification, are permitted provided that the following
//conditions are met:
//
//* Redistributions of source code must retain the above
//  copyright notice, this list of conditions and the
//  following disclaimer.
//* Redistributions in binary form must reproduce the
//  above copyright notice, this list of conditions and
//  the following disclaimer in the documentation and/or
//  other materials provided with the distribution.
//* Neither the name of the developer nor the names
//  of its contributors may be used to endorse or promote
//  products derived from this software without specific
//  prior written permission.
//
//THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
//CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
//INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
//MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
//DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
//SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
//BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
//INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
//WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
//OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
//SUCH DAMAGE.
//---------------------------------------------------------------


public class RTMPView extends MhtvsActivity {

	private VideoView mVideoView;
	protected static final String Status = null;
	/** Called when the activity is first created. */
    @Override
    // HANDLE DEFAULT PHONE KEY EVENTS
    //do not reload page on orientation switch or keyboard slide -- keep current page as it is!!
    public void onConfigurationChanged(Configuration newConfig){
    	super.onConfigurationChanged(newConfig);
    	
    	   if(newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO){
    	       //slideout detected
    		   super.onConfigurationChanged(newConfig);
    	   }
    	   if(newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES){
    	       //slideout detected
    		   super.onConfigurationChanged(newConfig);
    	   }	
    }

    protected void onCreate(Bundle savedInstanceState) {    	
        super.onCreate(savedInstanceState);
        // set to fullscreen
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);        
        Tunnel t=new Tunnel();
        try{ 
        	t.go(); 
			setContentView(R.layout.rtmp);
			VideoView videoView = (VideoView) findViewById(R.id.videoView1);
			MediaController mediaController = new MediaController(this);
			mediaController.setAnchorView(videoView);
			// Set video link (mp4 format )
			Uri video = Uri.parse("rtsp://192.168.3.103:4555/stream.avi");
			videoView.setMediaController(mediaController);
			videoView.setVideoURI(video);
			videoView.start();			                
        } catch(Exception ex) { 
        	ex.printStackTrace(); 
			setContentView(R.layout.rtmpfail);
	}
        
  	}
  		
    @Override
    protected void onStart() {
        super.onStart();
    }
    @Override
    public void onRestoreInstanceState(Bundle savedInstanceState) {
    	super.onRestoreInstanceState(savedInstanceState);
    	//Toast.makeText(this, "RESTORED!", Toast.LENGTH_LONG).show();
    }
    @Override
    public void onRestart() {
    	super.onRestart();
    	//Toast.makeText(this, "RESTARTED!", Toast.LENGTH_LONG).show();
    }
    @Override
    protected void onResume() {
        super.onResume();
        //Toast.makeText(this, "RESUMED!", Toast.LENGTH_LONG).show();
    }    
    @Override
    protected void onSaveInstanceState(Bundle savedInstanceState) {
        super.onSaveInstanceState(savedInstanceState); // the UI component values are saved here.
        //Toast.makeText(this, "Activity state saved", Toast.LENGTH_LONG).show();
    }
    @Override
    protected void onPause() {
        super.onPause();
        //Toast.makeText(this, "PAUSED!", Toast.LENGTH_LONG).show();
    }
    @Override
    protected void onStop() {
        super.onStop();
        //Toast.makeText(this, "STOPPED!", Toast.LENGTH_LONG).show();
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        //Toast.makeText(this, "Activity is getting killed", Toast.LENGTH_LONG).show();
    }
}
